home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Report Error 2.0 / ModalScrollText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  3.9 KB  |  170 lines  |  [TEXT/KAHL]

  1. /*================================================================================
  2.     modalScrollText.c
  3.     
  4.     circa 1991 by Greg Anderson
  5.     greggor@apple.com
  6.     
  7.     FREE DISTRIBUTION--use and enjoy
  8.     
  9.     This file contains routines that display a modal dialog box
  10.     containing a scrolling item list
  11. ================================================================================*/
  12. #include "ModalScrollText.h"
  13.  
  14. #include "DialogUtilities.h"
  15. #include "TEUtilities.h"
  16. #include "FailureHandler.h"
  17.  
  18. /*----------------------------------------------------------------------
  19.     ScrollingTextFilter
  20.  
  21.     This ModalDialogProc has two functions:
  22.     
  23.         1. It handles clicks in the SplashScreen's scrollbar
  24.         2. It eats keydown events so that the user cannot edit
  25.            the text of the About Box.
  26. ----------------------------------------------------------------------*/
  27. pascal Boolean ScrollingTextFilter( DialogPtr dlog, EventRecord* event, short* itemHit )
  28. {
  29.     ControlHandle    scrollbar;
  30.     TEHandle        te;
  31.     Point            localClick;
  32.     short            itemType;
  33.     short            theItem;
  34.     Handle            itemHandle;
  35.     Rect            box;
  36.  
  37.     SetPort(dlog);
  38.     
  39.     GetDItem( dlog, kScrollbarItem, &itemType, (Handle*)&scrollbar, &box );
  40.     te = (TEHandle)GetCRefCon( scrollbar );
  41.     /*
  42.     // Handle clicks in the scrollbar
  43.     */
  44.     localClick = event->where;
  45.     GlobalToLocal( &localClick );
  46.     if( event->what == mouseDown )
  47.     {
  48.         theItem = FindDItem(dlog,localClick) + 1;
  49.         if( theItem == kScrollbarItem )
  50.         {
  51.             ScrollBarClick( scrollbar, localClick );
  52.             *itemHit = theItem;
  53.             return true;
  54.         }
  55.         if( theItem == kEditTextItem )
  56.         {
  57.             Point        mousePt;
  58.             
  59.             GetMouse( &mousePt );
  60.             TEClick( mousePt, false, te );
  61.             FixScrollBar( scrollbar );
  62.  
  63.             return true;
  64.         }
  65.     }
  66.     /*
  67.     // Check to see if the RETURN key was pressed
  68.     */
  69.     if( event->what == keyDown )
  70.     {
  71.         char    key = (char)(event->message & charCodeMask);
  72.         
  73.         if( key == '\r' )
  74.         {
  75.             *itemHit = 1;
  76.             return true;
  77.         }
  78.         /*
  79.         // We want to eat any keyDown event that is not a Return,
  80.         // a cut or a copy
  81.         */
  82.         else if( (event->modifiers & cmdKey) && ((key == 'c') || (key == 'x')) )
  83.         {
  84.             /*
  85.             // Translate 'cut' into 'copy'
  86.             */
  87.             event->message = (event->message & ~ charCodeMask) | 'c';
  88.         }
  89.         /*
  90.         // Transmogrify the keyDown event into a null event
  91.         // because we want to ignore it
  92.         */
  93.         else
  94.         {
  95.             event->what = nullEvent;
  96.         }
  97.     }
  98.     
  99.     return CutPasteFilter( dlog, event, itemHit );
  100. }
  101.  
  102. /*----------------------------------------------------------------------
  103.     ModalScrollText
  104. ----------------------------------------------------------------------*/
  105. void ModalScrollText( Str255 title, Ptr textToShow, Size lengthOfText )
  106. {
  107.     DialogPtr        dlog;
  108.     TEHandle        te;
  109.     ControlHandle    scrollbar;
  110.     Handle            itemHandle;
  111.     short            itemType;
  112.     Rect            box;
  113.     short            itemHit;
  114.     
  115.     dlog = nil;
  116.     
  117.     TRY
  118.     {
  119.         /*
  120.         // Set up Dialog box
  121.         */
  122.         dlog = GetNewDialog( kModalScrollID, (Ptr)0L, (WindowPtr)-1L);
  123.         FailResErrorOrNil( dlog );
  124.         SetPort(dlog);
  125.         ParamText( title, nil, nil, nil );
  126.         InstallDefaultOutline(dlog,1);
  127.         CenterAndShowDialog(dlog);
  128.         /*
  129.         // Set the text of the currently open textedit item
  130.         // (the first one will be selected...)
  131.         */
  132.         GetDItem( dlog, kEditTextItem, &itemType, &itemHandle, &box );
  133.         te = ((DialogRecord*)dlog)->textH;
  134.         TESetText( textToShow, lengthOfText, te );
  135.         /*
  136.         // Get a reference to the scrollbar & set its refCon
  137.         // to the textEdit item it controls
  138.         */
  139.         GetDItem( dlog, kScrollbarItem, &itemType, (Handle*)&scrollbar, &box );
  140.         SetCRefCon( scrollbar, (long)te );
  141.         /*
  142.         // Select and draw the window
  143.         */
  144.         SelectWindow(dlog);
  145.         SetPort(dlog);
  146.         DrawDialog(dlog);
  147.         /*
  148.         // Wait for user to click "Okay"
  149.         */
  150.         do
  151.         {
  152.             ModalDialog( (ProcPtr)ScrollingTextFilter, &itemHit );
  153.             /*
  154.             // This is necessary to fix up the scrollbar
  155.             // after an autoscroll.
  156.             */
  157.             //if( itemHit == kEditTextItem )
  158.             //    FixScrollBar( scrollbar );
  159.         } while( itemHit != 1 );
  160.         DisposDialog(dlog);
  161.     }
  162.     EXCEPT
  163.     {
  164.         if( dlog != nil )
  165.             DisposDialog(dlog);
  166.         DebugStr( "\pCould not bring up dialog box" );
  167.     }
  168.     ENDTRY
  169. }
  170.